//
//  HYSettingCell.m
//  HaiYue
//
//  Created by skyline on 2018/1/19.
//  Copyright © 2018年 skyline. All rights reserved.
//

#import "HYSettingCell.h"
@interface HYSettingCell ()
@property (nonatomic, strong) HYImageView *IMG;
@property (nonatomic, strong) HYLabel *label;
@end
@implementation HYSettingCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.separatorInset = UIEdgeInsetsZero;
    }
    return self;
}

- (HYImageView *)IMG
{
    if (!_IMG)
    {
        _IMG = [[HYImageView alloc] init];
        [self addSubview:_IMG];
        [_IMG mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(GAP);
            make.top.equalTo(self).with.offset(GAP * 1.5);
            make.bottom.equalTo(self).with.offset(-GAP*1.5);
            make.width.mas_equalTo(HYSettingCellHeight - 3 * GAP);
        }];
    }
    return _IMG;
}

- (HYLabel *)label
{
    if (!_label)
    {
        _label = [[HYLabel alloc] initWithText:@"" textColor:TEXT_BLACK_COLOR textFont:[UIFont systemFontOfSize:15]];
        [self addSubview:_label];
        [_label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.left.equalTo(self.IMG.mas_right).with.offset(GAP);
        }];
    }
    return _label;
}

- (UISwitch *)switchBtn
{
    if (!_switchBtn)
    {
        _switchBtn = [[UISwitch alloc] init];
        _switchBtn.onTintColor = THEME_COLOR;
        [_switchBtn addTarget:self action:@selector(actionForSettingSwitch) forControlEvents:UIControlEventValueChanged];
        [self addSubview:_switchBtn];
        [_switchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.right.equalTo(self).with.offset(-GAP);
        }];
    }
    return _switchBtn;
}

- (HYLabel *)contentLBL
{
    if (!_contentLBL)
    {
        _contentLBL = [[HYLabel alloc] initWithText:@"" textColor:TEXT_BLACK_COLOR textFont:[UIFont systemFontOfSize:13]];
        [self addSubview:_contentLBL];
        [_contentLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.right.equalTo(self).with.offset(-GAP);
        }];
    }
    return _contentLBL;
}

- (void)setTitle:(NSString *)title
{
    if (_title != title)
    {
        _title = title;
        self.label.text = title;
    }
}

- (void)setImageName:(NSString *)imageName
{
    if (_imageName != imageName)
    {
        _imageName = imageName;
        self.IMG.image = [UIImage imageNamed:_imageName];
    }
}

- (void)actionForSettingSwitch
{
    [_switchBtn becomeFirstResponder];
    _switchBtn.on = !_switchBtn.on;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}

@end
